package com.cytech.cloudclinic.moudle.main.setting.prescription.group;

import com.cytech.cloudclinic.base.BaseBean;
import com.cytech.cloudclinic.base.BaseObserver;
import com.cytech.cloudclinic.base.BasePresenter;
import com.cytech.cloudclinic.bean.PrescriptionTag;
import com.cytech.cloudclinic.bean.req.DemoInfo;
import com.cytech.cloudclinic.utils.RequestWithViewUtils;
import com.yechaoa.yutils.ToastUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class PrescriptionGroupPresenter extends BasePresenter<PrescriptionGroupView> {
    public PrescriptionGroupPresenter(PrescriptionGroupView baseView) {
        super(baseView);
    }
    //获取处方列表
    public void getPrescriptionTags(int drugParentTag) {
        JSONObject json = new JSONObject();
        try {
            json.put("drug_tag",drugParentTag);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String requestStr = json.toString();
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestStr);
        RequestWithViewUtils.getInstance().addDisposable(RequestWithViewUtils.getInstance().apiServer.getPrescriptionTags(body), new BaseObserver<BaseBean<List<PrescriptionTag>>>(null, true) {

            @Override
            public void onSuccess(BaseBean<List<PrescriptionTag>> o) {
                baseView.getPresciptionListSuccess(o.result);
            }

            @Override
            public void onError(String msg) {
                ToastUtil.showToast(msg);
            }
        });
    }
}
